module Song
  class Song
    attr_writer:duration
    attr_accessor :name, :artist,:duration
    @@plays=0
    def initialize(name,artist, duration)
      @name,@artist,@duration = name,artist,duration
      @plays = 0
    end

    def durationInMinutes
      @duration /60.0
    end
    def durationInMinutes=(value)
      @duration = (value*60).to_i
    end

    def play
      @plays += 1
      @@plays += 1
      "This song: #@plays plays. total #@@plays plays."
    end

    def to_s
      "Song:#{@name}--#{@artist} (#{@duration})"
    end
  end

  class SongList
    MaxTime = 5*60
    attr_accessor :songs
    def initialize;    @songs = Array.new;      end
    def append(aSong); @songs.push(aSong); self end
    def deleteFirst;   @songs.shift;            end
    def deleteLast;    @songs.pop;              end

    def [](key)
      return @songs[key] if key.kind_of?(Integer)
      return @songs.find {|aSong| aSong.name == key}
    end

    def SongList.isTooLong(aSong)
      aSong.duration > MaxTime
    end
  end
end